  <%match = Match.find(sid)%>
  <%match_not_placed =  !(@user||current_user).bets.map{|b| b.match_id}.include?(sid.to_i)%>
 <!--place challenge-->
   <%fb_dialog "dialog_#{sid.to_s + (u.nil? ? "" : "_" + u.id.to_s)}",1 do %>
    <%=fb_dialog_title "Send challenge to #{u.name rescue "..."}?"%>
    <%fb_dialog_content do%>
       <form id="my_form_<%=sid.to_s + (u.nil? ? "" : "_" + u.id.to_s)%>" >
        <table>
	       <tr>
	       <td class='dialog-text'>To:</td><td>
		  <%if u%>
		    <%=u.name%>
		    <input type=hidden name="to_user_id" value="<%=u.id%>">
		  <%else%>
		     <select name="to_user_id">
		      <%=options_from_collection_for_select (@other_friends||current_user.other_friends(sid)),:id,:name%>
		     </select>
		  <%end%>
	       </td>
	       </tr>
	       <%if match_not_placed%>
	       <tr>
		       <td class='dialog-text'>Your bet:</td>
		       <td>
			  <input type=hidden name="match_id" value="<%=sid%>">
			  <input type=radio name=team_id value=<%=match.home_team.id%> checked> <%=match.home_team.displayed_name + " ("+ "handicap" + " )" %><br/>
			  <input type=radio name=team_id value=<%=match.away_team.id%>> <%=match.away_team.displayed_name + " ("+ "handicap" + " )" %>
		       </td>
	       </tr>
	       <%else%>
	       <tr>
		<td class='dialog-text'>Your bet:</td><td><%=current_user.bet(match).team.displayed_name%></td></tr>
	       <%end%>
	       <tr>
		<td class='dialog-text'>Amount:</td>
		       <td> 
			 <input type=text style="width:30px" name="amount" value=100> WinPoints<span class='dialog-text'> (max. 500)</span>
			 <input type=hidden name="sid" value="<%=sid%>">
			 <input type=hidden name="sport_id" value="<%=match.sport_id%>">
		       </td>
	       </tr>
	       <tr>
		   <td colspan=2 class='dialog-text'>Message:<br/><p></p>
		      <textarea name="message" style="width:410px;height:40px;">You will not beat me!</textarea>
		      <div id="indicator_submit_<%=sid%>" style="display:none"><img src="http://<%=@call_back_url%>/images/indicator.gif"/>
		      </div>
		   </div>
		   </td>
	       </tr>
       </table>
	<p></p>
      </form>
    <%end%>



       <fb:dialog-button type="submit" value="Send Challenge" clicktoshow="indicator_submit_<%=sid%>,ssss_<%=sid%>" clickrewriteurl="http://<%=@call_back_url%>/friends_bet/sent" clickrewriteid="<%="dialog_#{sid.to_s + (u.nil? ? "" : "_" + u.id.to_s)}"%>" clickrewriteform="my_form_<%=sid.to_s + (u.nil? ? "" : "_" + u.id.to_s)%>" />

  <%end%> <!--of fb_dialog-->
